package com.dgut.lab.security;

import com.dgut.lab.entity.User;
import com.dgut.lab.mapper.UserRepository;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import javax.annotation.Resource;

public class SecurityUserDetailsService implements UserDetailsService {
    @Resource
    UserRepository userRepository;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user =  userRepository.findByUsername(username);
        if(user==null)
            throw new UsernameNotFoundException("username："+username+"Not Found");
        SecurityUserDetails securityUserDetails = new SecurityUserDetails();
        securityUserDetails.setUserInfo(user);
        return securityUserDetails;
    }
}
